package IO;

import java.io.*;

/**
 * @author 15594
 */
public class BufferedWriterReader {
    public static void main(String[] args) {
        File file = new File("test.txt");
        File file1 = new File("test-copy.txt");

        copy(file,file1);

    }

    private static void copy(File file, File file1) {

        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        try {
            FileReader fileReader = new FileReader(file);
            FileWriter fileWriter = new FileWriter(file1);
            bufferedReader = new BufferedReader(fileReader);
            bufferedWriter = new BufferedWriter(fileWriter);
            int len = 0;
            char[] chars = new char[10];

            bufferedWriter.newLine();
            while ((len = bufferedReader.read(chars))!=-1){
                bufferedWriter.write(chars,0,len);

            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bufferedReader!=null){
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bufferedWriter!=null){
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
